﻿using System.IO;
using DWORD = System.UInt64;

namespace Community.CsharpSqlite.Entity
{
    /*
    ** This subclass is a subclass of sqlite3_file.  Each open memory-journal
    ** is an instance of this class.
    */

    public partial class sqlite3_file
    {
        //public sqlite3_io_methods pMethods; /* Parent class. MUST BE FIRST */
        public FilePoint endpoint; /* Pointer to the end of the file */
        public FileChunk pFirst; /* Head of in-memory chunk-list */
        public FilePoint readpoint; /* Pointer to the end of the last xRead() */
    };

    /*
    ** The winFile structure is a subclass of sqlite3_file* specific to the win32
    ** portability layer.
    */
    //typedef struct sqlite3_file sqlite3_file;
    public partial class sqlite3_file
    {
        public FileStream fs; /* Filestream access to this file*/
        // public HANDLE h;            /* Handle for accessing the file */
        public int locktype; /* Type of lock currently held on this file */
        public int sharedLockByte; /* Randomly chosen byte used as a shared lock */
        public DWORD lastErrno; /* The Windows errno from the last I/O error */
        public DWORD sectorSize; /* Sector size of the device file is on */
#if SQLITE_OS_WINCE
WCHAR *zDeleteOnClose;  /* Name of file to delete when closing */
HANDLE hMutex;          /* Mutex used to control access to shared lock */
HANDLE hShared;         /* Shared memory segment used for locking */
winceLock local;        /* Locks obtained by this instance of sqlite3_file */
winceLock *shared;      /* Global shared lock memory for the file  */
#endif

        public void Clear()
        {
            pMethods = null;
            fs = null;
            locktype = 0;
            sharedLockByte = 0;
            lastErrno = 0;
            sectorSize = 0;
        }
    };

    /*
    ** CAPI3REF: OS Interface Open File Handle
    **
    ** An [sqlite3_file] object represents an open file in the 
    ** [sqlite3_vfs | OS interface layer].  Individual OS interface
    ** implementations will
    ** want to subclass this object by appending additional fields
    ** for their own use.  The pMethods entry is a pointer to an
    ** [sqlite3_io_methods] object that defines methods for performing
    ** I/O operations on the open file.
    */
    //typedef struct sqlite3_file sqlite3_file;
    //struct sqlite3_file {
    //  const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
    //};
    public partial class sqlite3_file
    {
        public sqlite3_io_methods pMethods; /* Must be first */
    }
}